package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"kim/service"
	"strconv"
)

type ApiController struct {
}

func (ApiController) Register(ctx *gin.Context) {

}

func (ApiController) Login(ctx *gin.Context) {

}

func (ApiController) AddUserToGroup(ctx *gin.Context) {

	userId := ctx.PostForm("userId")
	groupId := ctx.PostForm("groupId")
	fmt.Printf("获取到的用户%s  群聊%s \r", userId, groupId)
	uid, _ := strconv.Atoi(userId)
	gid, _ := strconv.Atoi(groupId)

	service.AddUserToGroup(int64(uid), int64(gid))

}

func (ApiController) DeleteUserFromGroup(ctx *gin.Context) {

}

func (ApiController) GetGroupsByUserId(ctx *gin.Context) {
	id, _ := strconv.Atoi(ctx.Query("userId"))
	userId := int64(id)
	groupIds := service.GetGroupsByUserId(userId)
	ctx.JSON(200, groupIds)

}
